<?php
$page=$_GET['page']??1;
$limit=3;
$start=($page-1)*$limit;
$dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
$sql="select * from movie limit $start,$limit";
$arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$movie_name=$_GET['movie_name']??'';
if($movie_name!='')
{
    $memcache_obj=memcache_connect('127.0.0.1',11211);
    $arr=$memcache_obj->get($movie_name);
    if($arr=='')
    {
        echo "没有缓存";
        $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
        $sql="select * from movie  where movie_name like '%$movie_name%' limit $start,$limit";
        $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
        $memcache_obj->set($movie_name,$arr);
    }
//    else{
//        $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
//        $sql="select * from movie  where movie_name like '%$movie_name%' limit $start,$limit";
//        $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
//    }

}
?>
<table border="1">
    <tr>
        <td>电影编号</td>
        <td>电影网址</td>
        <td>电影名称</td>
        <td>电影简介</td>
        <td>电影评分</td>
        <td>操作</td>

    </tr>
    <?php foreach($arr as $key=>$value) { ?>
        <tr>
            <td><?php echo $value['id']?></td>
            <td><?php echo $value['movie_url']?></td>
            <td><?php echo $value['movie_name']?></td>
            <td><?php echo $value['movie_jianjie']?></td>
            <td><?php echo $value['movie_score']?></td>
            <td>
                <a href="jth.php?id=<?php echo $value['id']?>">静态化</a>
            </td>
        </tr>
    <?php } ?>
</table>
<form method="get">
    <table>
        <tr>
            <td><input type="text" name="movie_name"></td>
            <td><input type="submit" value="搜素"></td>
        </tr>
    </table>
</form>
<a href="zhanshi.php?page=1">首页</a>
<a href="zhanshi.php?page=<?php echo $page-1?>&movie_name=<?php echo $movie_name?>">上一页</a>
<a href="zhanshi.php?page=<?php echo $page+1?>&movie_name=<?php echo $movie_name?>">下一页</a>

